//
//  ShareSortViewController.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/27.
//

#import "ShareSortViewController.h"
#import "CommonUtil.h"
#import "PingTeHeaderView.h"
#import "SortTableViewCell.h"
#import "SortModel.h"
#import "ShareSortHeaderView.h"

@interface ShareSortViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) UIColor * originbarTintColor;
@property (strong, nonatomic) UIView * bgView;
@property (strong, nonatomic) ShareSortHeaderView * headerView;
@property (strong, nonatomic) UITableView * tableView;
@property (strong, nonatomic) NSMutableArray * models;
@property (strong, nonatomic) UIView * bottomView;

@end

@implementation ShareSortViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
 
    if (self.sortMode == ShareSortShare) {
        self.navigationItem.title = @"分享排行榜";
    }else if (self.sortMode == ShareSortLiked){
        self.navigationItem.title = @"粉丝排行榜";
    }else if (self.sortMode == ShareSortContribution){
        self.navigationItem.title = @"贡献榜";
    }else if (self.sortMode == ShareSortCharm){
        self.navigationItem.title = @"魅力榜";
    }
    
    
    self.view.backgroundColor =  RGB(243.0, 243.0, 243.0);
    self.originbarTintColor = self.navigationController.navigationBar.barTintColor;
  
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomView];
    [self testData];
    
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barTintColor = RGB(234.0, 134.0, 79.0);
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19], NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.barTintColor = self.originbarTintColor;
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setShadowImage:nil];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19], NSForegroundColorAttributeName:[UIColor blackColor]}];
}


// 假数据
- (void)testData{
    self.models = [NSMutableArray array];
    for (NSInteger i = 0; i < 13; i++) {
        SortModel *model = [[SortModel alloc] init];
        model.sortIndex = i;
        
        
        [self.models addObject:model];
    }
    self.headerView.models = self.models;
    [self.tableView reloadData];
}


#pragma mark - UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.models.count-3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SortTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.model = self.models[indexPath.row + 3];
    return cell;
}

#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return AD(80);
}



-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-kNavBarAndStatusBarHeight-AD(100))];
        [_tableView registerClass:[SortTableViewCell class] forCellReuseIdentifier:@"cell"];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = self.headerView;
        _tableView.backgroundColor = RGB(234.0, 134.0, 79.0);
   
       
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//iOS11系统及以上，
        } else {
            self.automaticallyAdjustsScrollViewInsets = NO;
            // Fallback on earlier versions
        }
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

-(ShareSortHeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[ShareSortHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, AD(240))];
    }
    return _headerView;
}

-(UIView *)bottomView{
    if (!_bottomView) {
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0,self.tableView.bottom , SCREEN_WIDTH, AD(100))];
        _bottomView.backgroundColor = [UIColor whiteColor];
        _bottomView.layer.shadowColor = [UIColor blackColor].CGColor;
        _bottomView.layer.shadowRadius= AD(3);
        _bottomView.layer.shadowOpacity = 0.3f;
        _bottomView.layer.shadowOffset = CGSizeMake(0,0);
        
        UIImageView *iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"statistics_default.jpg"]];
        CGFloat w = AD(50);
        iconImageView.frame = CGRectMake(AD(80),AD(5), w, w);
        iconImageView.layer.cornerRadius = w/2;
        iconImageView.clipsToBounds = YES;
        [_bottomView addSubview:iconImageView];
        
        UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(AD(10), 0, AD(60), AD(20))];
        label1.text = @"100+";
        label1.textColor = [UIColor blackColor];
        label1.font = [UIFont systemFontOfSize:AD(18)];
        label1.textAlignment = NSTextAlignmentRight;
        label1.centerY = iconImageView.centerY;
        [_bottomView addSubview:label1];
        
        UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(iconImageView.right + AD(10), AD(10), AD(50), AD(20))];
        label2.text = @"我";
        label2.textColor = [UIColor blackColor];
        label2.font = [UIFont systemFontOfSize:AD(18)];
        [_bottomView addSubview:label2];
        
        UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(iconImageView.right + AD(10), label2.bottom + AD(5), AD(30), AD(20))];
        label3.text = @"0";
        label3.textColor = RGB(255.0, 90.0, 117.0);
        label3.font = [UIFont systemFontOfSize:AD(18)];
        [_bottomView addSubview:label3];
        [label3 sizeToFit];
        
        UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(label3.right + AD(5), AD(10), AD(50), AD(20))];
        label4.text = @"粉丝";
        label4.textColor = [UIColor lightGrayColor];
        label4.font = [UIFont systemFontOfSize:AD(13)];
        label4.bottom = label3.bottom;
        [_bottomView addSubview:label4];
        
    }
    return _bottomView;
}

@end
